﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IronOne.SalesOne.SalesOneWeb.UserControls
{
    public partial class UCGridButtons : System.Web.UI.UserControl
    {
        private static string[] dispButs;


        public string[] Buttons
        {
            get { return dispButs; }
            set { dispButs = value; }
        }
        


        protected void Page_Load(object sender, EventArgs e)
        {

            /*if (Buttons != null)
            {
                for (int i = 0; i < Buttons.Length; i++)
                {
                    switch (Buttons[i])
                    {
                        case "btnView":
                            btnView.Visible = true;
                            break;
                        case "btnCreate":
                            btnCreate.Visible = true;
                            break;
                        case "btnUpdate":
                            btnUpdate.Visible = true;
                            break;
                        case "btnDelete":
                            btnDelete.Visible = true;
                            break;
                        case "btnCancel":
                            btnCancel.Visible = true;
                            break;
                        default:
                            break;
                    }

                    
                }

            }*/

        }

        public void SetCredentials(StringCollection credential)
        {
            foreach (string item in credential)
            {
                switch (item.ToLower())
                {
                    case "c" :
                        btnCreate.Visible = true;
                        break;
                    case "u" :
                        btnUpdate.Visible = true;
                        break;
                    case "d" :
                        btnDelete.Visible = true;
                        break;
                    case "v" :
                        btnView.Visible = true;
                        break;
                    default:
                        break;
                }
            }
        }


        protected void btnView_Click(object sender, EventArgs e)
        {

            if (this.Page is IDataPage)
                ((IDataPage)this.Page).View();


            //string pageUrl = Request.ServerVariables["URL"];
            //string action = "view";
            //string id = string.Empty;

            
            //UCUserGrid grd = new UCUserGrid();
            //GridView grdView = (GridView)grd.FindControl("grdUsers");

            //switch (pageUrl)
            //{
            //    case "/UserManagement/ManageUsers.aspx":
            //        Session["UserAc"] = "view";
            //        Response.Redirect("~/UserManagement/AddUser.aspx");
            //        break;
            //    case "/UserManagement/SearchUsers.aspx":
            //        Session["UserAc"] = "view";
            //        Response.Redirect("~/UserManagement/AddUser.aspx");
            //        break;

            //    case "/UserManagement/ManageGroups.aspx":
            //        Session["UserAc"] = "view";
            //        Response.Redirect("~/UserManagement/AddGroup.aspx");
            //        break;

            //    case "/Structure/ManageUnits.aspx":
            //        Session["UnitAc"] = "View";
            //        Response.Redirect("/Structure/AddUnit.aspx");
            //        break;

            //    case "/Structure/ManageBranches.aspx":
            //        Session["BranchAc"] = "View";
            //        Response.Redirect("/Structure/AddBranch.aspx");
            //        break;

                

            //    default:
            //        break;
            

            


            //id = Request.Form["gvradio"].ToString();
            //Response.Write(id);
          
                
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).Update();

            //DropDownList dlupdate = (DropDownList)this.Parent.FindControl("TypeDropDownList");
            //string pageUrl = Request.ServerVariables["URL"];

            //switch (pageUrl)
            //{
            //    case "/UserManagement/ManageUsers.aspx":
            //        Session["UserAc"] = "update";
            //        Response.Redirect("~/UserManagement/UpdateUser.aspx");
            //        break;

            //    case "/Structure/ManageBranches.aspx":
            //        Session["BranchAc"]="Update";
            //        Response.Redirect("/Structure/AddBranch.aspx");
            //        break;

            //    case "/Structure/ManageUnits.aspx":
            //        Session["UnitAc"] = "Update";
            //        Response.Redirect("/Structure/AddUnit.aspx");
            //        break;

            //    case "/UserManagement/SearchUsers.aspx":
            //        Session["BranchAc"] = "Update";
            //        Response.Redirect("/UserManagement/UpdateUser.aspx");
            //        break;

            //    case "/UserManagement/ManageGroups.aspx":
            //        Session["UserAc"] = "update";
            //        Response.Redirect("~/UserManagement/AddGroup.aspx");
            //        break;

            //    case "/UserManagement/CodeType.aspx":
            //        Session["UserAc"] = "update";
            //        Response.Redirect("/UserManagement/ManageCodeTypeUpdate.aspx?codetypeupdate=" + dlupdate.SelectedValue, false);
            //        break;

               


            //    default:
            //        break;
            //}
            

        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).Create();

            //DropDownList dlcreate = (DropDownList)this.Parent.FindControl("TypeDropDownList");
            //string pageUrl = Request.ServerVariables["URL"];

            //switch (pageUrl)
            //{
            //    case "/UserManagement/ManageUsers.aspx":
            //        Session["UserAc"] = "create";
            //        Response.Redirect("~/UserManagement/AddUser.aspx");
            //        break;

            //    case "/UserManagement/SearchUsers.aspx":
            //        Session["UserAc"] = "create";
            //        Response.Redirect("~/UserManagement/AddUser.aspx");
            //        break;

            //    case "/UserManagement/ManageGroups.aspx":
            //        Session["UserAc"] = "create";
            //        Response.Redirect("~/UserManagement/AddGroup.aspx");
            //        break;

            //    case "/Structure/ManageBranches.aspx":
            //        Session["BranchAc"] = "Create";
            //        Response.Redirect("/Structure/AddBranch.aspx");
            //        break;

            //    case "/Structure/ManageUnits.aspx":
            //        Session["UnitAc"] = "Create";
            //        Response.Redirect("/Structure/AddUnit.aspx");
            //        break;
            //    case "/UserManagement/CodeType.aspx":
            //        Session["UserAc"] = "create";
            //        Response.Redirect("/UserManagement/ManageCodeTypeCreate.aspx?codetypecreate=" + dlcreate.SelectedValue, false);
            //        break;

                
                

            //    default:
            //        break;
            //}

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).Delete();

            //string strNextURl = "";
            //string pageUrl = Request.ServerVariables["URL"];

            //switch (pageUrl)
            //{
            //    case "/UserManagement/ManageUsers.aspx":
            //        Session["UserAc"] = "delete";
            //        Response.Redirect("~/UserManagement/AddUser.aspx");
            //        break;

            //    case "/UserManagement/ManageGroups.aspx":
            //        Session["UserAc"] = "delete";
            //        Response.Redirect("~/UserManagement/AddGroup.aspx");
            //        break;

            //    case "/Structure/ManageUnits.aspx":
            //        Session["UnitAc"] = "Delete";
            //        Response.Redirect("/Structure/AddUnit.aspx");
            //        break;

            //    case "/Structure/ManageBranches.aspx":
            //        Session["BranchAc"] = "Delete";
            //        Response.Redirect("/Structure/AddBranch.aspx");
            //        break;

            //    case "/UserManagement/CodeType.aspx":
            //        Session["UserAc"] = "delete";
            //        strNextURl = "/UserManagement/CodeType.aspx";               
            //        break;



            //    default:
            //        break;
            //}
            //Server.Transfer(strNextURl);
          
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).Cancel();
        }

        /*protected void btnManageUser_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).ManageUser();

        }

        protected void btnManageUnit_Click(object sender, EventArgs e)
        {
            if (this.Page is IDataPage)
                ((IDataPage)this.Page).ManageUnit();

        }*/



        //public string id
        //{
        //    get
        //    {
        //        return idVal;
        //    }
        //    set
        //    {
        //        idVal = value;
        //    }
        //}
    }
}